package com.dks.controller;

import com.dks.models.QsClass;
import com.dks.repository.IQsClassRepository;
import com.dks.result.Result;
import com.dks.result.ResultInfo;
import com.dks.result.ResultModel;
import com.dks.util.PageInfo;
import com.dks.vo.qsClass.QsClassVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RequestMapping("qs-class")
@RestController
public class QsClassController{

    private IQsClassRepository qsClassRepository;

    @Autowired
    public QsClassController(final IQsClassRepository qsClassRepositoryIn){
        this.qsClassRepository = qsClassRepositoryIn;
    }

    /**
     * @Author: Ah Nan
     * @Description: 老师上课
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: qsClassId 课程id
     * @Param: getLessonStartTime 上课时间+
     * @Param: AttendClassStatus 上课状态:0上课,1下课
     * @return:
     * @throw: 请描述异常信息
     */
    @PostMapping("add-class")
    public ResultModel<Object> addClass(@RequestBody QsClass qsClass) {

        if (null == qsClass.getId()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "课程id不能为空");
        }
//        if (null == qsClass.getTeacherId()) {
//            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "TeacherId");
//        }
//        if (null == qsClass.getLessonStartTime()) {
//            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "getLessonStartTime");
//        }
//        if (null == qsClass.getId()) {
//            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "qsClassId");
//        }
        //AttendClassStatus:上课状态:0上课,1下课
//        if (null == qsClass.getAttendClassStatus()) {
//            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "AttendClassStatus");
//        }

        return qsClassRepository.addClass(qsClass);
    }

    /**
     * @Author: Ah Nan
     * @Description: 老师下课
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: qsClassId 课程id
     * @Param: getLessonStartTime 上课时间+
     * @Param: AttendClassStatus 上课状态:0上课,1下课
     * @return:
     * @throw: 请描述异常信息
     */
    @PostMapping("class-is-over")
    public ResultModel<Object> classIsOver(@RequestBody QsClass qsClass) {

        if (null == qsClass.getId()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "课程id不能为空");
        }

        return qsClassRepository.classIsOver(qsClass);
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取首页课程列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: diaryId 日记id
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-qs-class-list")
    public ResultModel<Object> getCourseTeacherList() {

        return qsClassRepository.getCourseTeacherList();
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取待上课课程列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: diaryId 日记id
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-wait-qs-class-list")
    public ResultModel<Object> getWaitQsClassList() {

        return qsClassRepository.getWaitQsClassList();
    }

    /**
     * 班级筛选
     * 筛选条件：上课时间（startTime、endTime）、课程类型(courseCategory)、学生id（studentId）
     * @author evan
     */
    @GetMapping("list/screening")
    public ResultModel<PageInfo<QsClass>> listScreening(@RequestParam("startTime") LocalDateTime startTime, @RequestParam("endTime")LocalDateTime endTime,
                                                        @RequestParam("studentId")Integer studentId, @RequestParam("courseCategory")String courseCategory,
                                                        @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                        @RequestParam(value = "pageSize",defaultValue = "15") Integer pageSize){
        return qsClassRepository.listScreening(startTime, endTime, studentId, courseCategory, pageNum, pageSize);
    }

    /***
     * 根据id 获取班级信息
     * @author evan
     */
    @GetMapping("/detail")
    public ResultModel<QsClassVo> getDetail(@RequestParam("id")Long id, @RequestParam("userId")Long userId){
        if (id == null){
            return Result.makeResultAppend(ResultInfo.ERR_BASE_001, "id");
        }
        if (userId == null){
            return Result.makeResultAppend(ResultInfo.ERR_BASE_001, "userId");
        }
        return qsClassRepository.getDetail(id, userId);
    }

}
